<template>
  <transition :name="transition">
    <div class="weui-loading_toast vux-loading" v-show="show">
      <div class="weui-mask_transparent"></div>
      <div class="weui-toast" :style="{ position: position }">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content"><slot>加载中...</slot></p>
      </div>
    </div>
  </transition>
</template>

<i18n>
  loading:
  en: loading
  zh-CN: 加载中
</i18n>

<script>
  export default {
    name: 'loading',
    model: {
      prop: 'show',
      event: 'change'
    },
    props: {
      show: Boolean,
      text: String,
      position: String,
      transition: {
        type: String,
        default: 'vux-mask'
      }
    },
    watch: {
      show (val) {
        this.$emit('update:show', val)
      }
    }
  }
</script>

<style>
  .weui-loading {
    width: 20px;
    height: 20px;
    display: inline-block;
    vertical-align: middle;
    animation: weuiLoading 1s steps(12, end) infinite;
    background: transparent url("") no-repeat;
    background-size: 100%;
    &.weui-loading_transparent{
      background-image: url("");
    }
  }

  @-webkit-keyframes weuiLoading {
    0% {
      transform: rotate3d(0, 0, 1, 0deg);
    }

    100% {
      transform: rotate3d(0, 0, 1, 360deg);
    }
  }

  @keyframes weuiLoading {
    0% {
      transform: rotate3d(0, 0, 1, 0deg);
    }

    100% {
      transform: rotate3d(0, 0, 1, 360deg);
    }
  }
  .weui-toast {
    position: fixed;
    z-index: @toast-z-index;
    width: 7.6em;
    min-height: 7.6em;
    top: @toast-top;
    left: 50%;
    margin-left: -3.8em;
    background: rgba(17,17,17,0.7);
    text-align: center;
    border-radius: 5px;
    color: #FFFFFF;
  }
  .weui-icon_toast {
    margin: 22px 0 0;
    display: block;
    &.weui-icon-success-no-circle{
      &:before {
        color: #FFFFFF;
        font-size: 55px;
      }
    }
    &.weui-loading{
      margin:30px 0 0;
      width:38px;
      height:38px;
      vertical-align: baseline;
    }
  }

  .weui-toast__content {
    margin: 0 0 15px;
  }
  .weui-mask {
    position: fixed;
    z-index: 1000;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    background: rgba(0, 0, 0, .6);
  }

  .weui-mask_transparent{
    position: fixed;
    z-index: 1000;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
  }
  .vux-loading .weui-toast {
    z-index: 5001;
  }
  .weui-icon_toast.weui-loading {
    margin: 30px 0 0;
    width: 38px;
    height: 38px;
    vertical-align: baseline;
    display: inline-block;
  }
  .vux-mask-enter, .vux-mask-leave-active {
    opacity: 0;
  }
  .vux-mask-leave-active, .vux-mask-enter-active {
    transition: opacity 300ms;
  }
</style>
